import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

// 定义全局state
const state = {
  app: {
    ws: {},
    userList: [],
    chatUser: {},
    loginUser: {},
    newMessage: false,
    chatContent: []
  }
}

// 定义同步操作
const mutations = {
  // 设置show list
  APP_SET_WS (state, ws) {
    state.app.ws = ws
  },
  APP_SET_USER_LIST (state, userList) {
    state.app.userList = userList
  },
  APP_SET_CHAT_USER (state, chatUser) {
    state.app.chatUser = chatUser
  },
  APP_SET_LOGIN_USER (state, loginUser) {
    state.app.loginUser = loginUser
  },
  APP_SET_NEW_MESSAGE (state, newMessage) {
    state.app.newMessage = newMessage
  },
  APP_SET_CHAT_CONTENT (state, chatContent) {
    state.app.chatContent = chatContent
  }
}

// actions
const actions = {
  appSetWs ({commit}, ws) {
    commit('APP_SET_WS', ws)
  },
  appSetUserList ({commit}, userList) {
    commit('APP_SET_USER_LIST', userList)
  },
  appSetChatUser ({commit}, chatUser) {
    commit('APP_SET_CHAT_USER', chatUser)
  },
  appSetLoginUser ({commit}, loginUser) {
    commit('APP_SET_LOGIN_USER', loginUser)
  },
  appSetNewMessage ({commit}, newMessage) {
    commit('APP_SET_NEW_MESSAGE', newMessage)
  },
  appSetChatContent ({commit}, chatContent) {
    commit('APP_SET_CHAT_CONTENT', chatContent)
  }
}

export default new Vuex.Store({
  state,
  mutations,
  actions
  // getters
})
